﻿<!DOCTYPE html>
<html>
<head>
    <script src="/js/header.js"></script>
    <link href="/lib/jquery/jquery-ui.min.css" rel="stylesheet" />
    <script src="/lib/jquery/jquery-ui.min.js"></script>
</head>
<body>
    <div class="data-wrap case" id="container">
        <div class="data-tool clearfix">
            <div class="pull-left form-inline ">
                <a class="btn btn-default btn-sm" data-modal="/view/company/edit.html" data-title="新增" data-width="452" data-height="420"><span class="glyphicon glyphicon-plus"></span> 新增</a>
            </div>
            <div class="pull-right">
                <form class="form-inline" id="formSearch">

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">公司名称：</label>
                        <input class="form-control" name="CompanyName" type="text"/>
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">联络电话：</label>
                        <input class="form-control wd150" name="CompanyTel" type="text"/>
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">状态：</label>
                        <select class="form-control" name="CompanyStatus">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="2">禁用</option>
                        </select>
                    </div>

                    <button type="button" class="btn btn-default btn-sm active" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </form>
            </div>
        </div>
        <div class="paging">
        </div>

    </div>
    <script type="text/x-dot-template" id="templatePager">
        <div class="data-body data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table table-hover table-striped table-bordered">
                        <thead>
                            <tr>
                                <th class="t_l">公司名称</th>
                                <th class="t_l">公司英文名称</th>
                                <th class="t_l">联络负责人</th>
                                <th class="t_l">联络电话</th>
                                <th class="t_l">联络地址</th>
                                <th class="t_r">收款费率 (%)</th>
                                <th class="t_r">付款费率 (%)</th>
                                <th class="t_r">中转费率 (%)</th>
                                <th>状态</th>
                                <th width="350">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {{~it.result :item:index}}
                            <tr>
                                <td class="t_l">{{= item.companyName }}</td>
                                <td class="t_l">{{= item.companyNameEN }}</td>
                                <td class="t_l">{{= item.companyBossName }}</td>
                                <td class="t_l">{{= item.companyTel }}</td>
                                <td class="t_l">{{= item.companyAddress }}</td>
                                <td class="t_r">{{= FlashPay.Util.FormatNumber(item.depositRate*100,2) }} (%)</td>
                                <td class="t_r">{{= FlashPay.Util.FormatNumber(item.payRate*100,2) }} (%)</td>
                                <td class="t_r">{{= FlashPay.Util.FormatNumber(item.transportRate*100,2) }} (%)</td>
                                <td>{{= FlashPay.Util.GetStatusValue(item.companyStatus) }}</td>
                                <td width="350">
                                    {{? item.companyID!=item.updateUID}}
                                    {{? item.companyStatus==1 }}
                                    <a class="btn btn-default btn-xs btn-warning"
                                       data-confirm='"{{= item.companyName }}" <br>确定要<span class="orange">禁用</span>该公司吗？'
                                       data-href="/Company/ChangeStatus?CompanyID={{= item.companyID}}&CompanyStatus=2">禁用</a>
                                    {{?? }}
                                    <a class="btn btn-default btn-xs btn-success"
                                       data-confirm='"{{= item.companyName }}" <br>确定要<span class="green">启用</span>该公司吗？'
                                       data-href="/Company/ChangeStatus?CompanyID={{= item.companyID}}&CompanyStatus=1">启用</a>
                                    {{? }}
                                    {{? }}

                                    {{? it.permission.canDepositView || it.permission.canPaymentView || it.permission.canTransferView}}
                                    <button type="button" class="btn btn-default btn-xs" data-modal="/view/company/extapicompat.html?id={{= item.companyID}}" data-title="授权 - {{= item.companyName }}" data-width="660" data-height="615">
                                        <span class="glyphicon glyphicon-edit"></span> 接口授权
                                    </button>
                                    {{? }}

                                    {{? item.companyStatus!=3}}
                                    <button type="button" class="btn btn-default btn-xs" data-modal="/view/company/edit.html?id={{= item.companyID}}" data-title="编辑 - {{= item.companyName }}" data-width="452" data-height="420">
                                        <span class="glyphicon glyphicon-edit"></span> 编辑
                                    </button>
                                    {{? }}

                                    {{? item.companyStatus!=3 && item.companyID!=item.updateUID}}
                                    <a class="btn btn-default btn-xs btn-danger"
                                       data-confirm='"{{= item.companyName }}" <br>确定要<span class="red">删除</span>该公司吗？'
                                       data-href="/Company/Delete?CompanyID={{= item.companyID}}"><span class="glyphicon glyphicon-trash"></span>&nbsp;刪除</a>
                                    {{? }}
                                </td>
                            </tr>
                            {{~}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- 必要的分页参数设置 -->
        <input type="hidden" id="TotalCount" value="{{=it.totalCount}}" />
    </script>
    <script type="text/javascript">
        $(function () {
            FlashPay.UI.DataAutoHeight();

            FlashPay.UI.DoSearch();

            $("#btnSearch").click(function () {
                window.currentPage = null;
                doSearch();
            });
        });

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                FlashPay.UI.DoSearch();
            }
        });

        $("input[name='CompanyName']").autocomplete({
            minLength: 1,
            source: function (request, response) {
                FlashPay.Util.Ajax({
                    url: '/Role/CompanySearch',
                    type: 'POST',
                    data: { companyName: $("input[name='CompanyName']").val() },
                    success: function (res) {
                        if (res.success) {
                            if (res.data != null && res.data.length > 0) {
                                response($.map(res.data, function (item) {
                                    return {
                                        label: item.companyName,
                                        value: item.companyName,
                                        id: item.companyID
                                    }
                                }))
                            }
                        } else {
                            FlashPay.UI.Tip_warning("操作失败！" + res.errorMessage);
                        }
                    },
                    error: function (json) {
                        FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                    }
                });
            }
        });

        function doSearch() {
            FlashPay.UI.Pager(".paging", { templateId: "templatePager", pageSize: 15, ajax: { url: '/Company/Get', Method: 'Post' } });
        }
        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }
    </script>
</body>
</html>